# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libplacebo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.29.1
pkgrel=1
pkgdesc="Reusable library for GPU-accelerated video/image rendering primitives (mingw-w64)"
arch=('any')
url="https://github.com/haasn/libplacebo/"
depends=("${MINGW_PACKAGE_PREFIX}-vulkan"
         "${MINGW_PACKAGE_PREFIX}-spirv-tools")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-glslang"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
license=('LGPLv2.1')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/haasn/libplacebo/archive/v${pkgver}.tar.gz"
        0001-meson-fix-glslang-search-path.patch)
sha256sums=('ec8fed9ab1e9005917bf9f35b547d831548c63285d64ac965e7ad160579ab951'
            'f04ade294ff1e47767247899de34be4bb069fc359f94d5a6cc53faaca016f57a')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-meson-fix-glslang-search-path.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype plain \
    -Dglslang=enabled \
    -Dshaderc=disabled \
    ../${_realname}-${pkgver}

  ninja
}

package() {
  cd "${srcdir}"/build-${CARCH}
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  sed -e "s|${_PRE_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/libplacebo.pc
}
